package com.yanqu.road.server.cmd.badge;

import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.badge.BadgeProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.player.BadgeModule;
import com.yanqu.road.server.protocol.Protocol;

@Cmd(code = Protocol.S_BADGE_SET_DISPERSE_GOLD_SHOW, desc = "设置财神送礼展示")
public class SetDisperseGoldShowCmd extends AbstractCommand {

    private int badgeId;
    private int badgeType;
    private boolean disperseGoldShow;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        BadgeProto.SetDisperseGoldShowReqMsg reqMsg = BadgeProto.SetDisperseGoldShowReqMsg.parseFrom(packet.getBytes());
        badgeId = reqMsg.getBadgeId();
        badgeType = reqMsg.getBadgeType();
        disperseGoldShow = reqMsg.getDisperseGoldShow();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        ret = player.getModule(BadgeModule.class).setDisperseGoldShow(badgeId, badgeType, disperseGoldShow);
    }

    @Override
    public void sendData(GamePlayer player) {
        BadgeProto.SetDisperseGoldShowRespMsg.Builder respMsg = BadgeProto.SetDisperseGoldShowRespMsg.newBuilder();
        respMsg.setRet(ret);
        if (ret == 0) {
            respMsg.setDisperseGoldShow(disperseGoldShow);
        }
        player.sendPacket(Protocol.U_BADGE_SET_DISPERSE_GOLD_SHOW, respMsg);
    }
}
